package com.axapoint.opoc.core.dao;

import java.util.ArrayList;

import org.joda.time.DateTime;
import org.joda.time.Interval;

import com.axapoint.opoc.core.UserException;

public class OrganizationTypeFacade extends AbstractFacade<OrganizationType, OrganizationType.Value, OrganizationType.Bitemporal> {

	public OrganizationTypeFacade(String systemId, String userId) {
		super(systemId, userId, new OrganizationType(), new OrganizationType.Value());
	}
	
	public Organization.Value[] getOrganizations(String uuid, DateTime at) {
		OrganizationType ot = getEntity(uuid);
		if (ot == null) throw new UserException("Ukendt Organisation type UUID: " + uuid);
		
		ArrayList<Organization.Value> result = new ArrayList<Organization.Value>();
        for (Organization.Value v : ot.getOrganizations()) {
        	if (at == null || v.getBitemporal().getValidityInterval().contains(at)) {
        		result.add(v);
        	}
        }
		
		return result.toArray(new Organization.Value[0]);
	}

	@Override
	public ObjectRegistration[] getAffectedEntities(String uuid, Interval newInterval) {
		//XXX: implement
		return null;
	}
}
